﻿@{
    ViewBag.Title = "Login";
    Layout = null;
}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title id="page-title">@ViewBag.Title</title>
        <link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/ext/resources/css/ext-all.css")" />
        <link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/ext/resources/css/ext-all-gray.css")" />
        <link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/icons.css")" />
        <link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/icons32.css")" />
        <link rel="stylesheet" type="text/css" href="@Url.Content("~/Scripts/ideas2realize.css")" />
        <script type="text/javascript" src="@Url.Content("~/Scripts/ext/ext-all.js")"></script>
        <script type="text/javascript">

            Ext.onReady(function () {

                Ext.create('Ext.window.Window', {
                    title: 'Login',
                    width: 300,
                    height: 120,
                    draggable: false,
                    resizable: false,
                    closable: false,
                    items: [
                        {
                            xtype: 'form',
                            bodyCls: 'padd-up',
                            border: false,
                            items: [
                                { xtype: 'textfield', fieldLabel: 'Username', name: 'Username', id: 'UsernameField' },
                                { xtype: 'textfield', fieldLabel: 'Password', name: 'Password', id: 'PasswordField', inputType: 'password' }
                            ]
                        }
                    ],
                    bbar: [
                        { xtype: 'checkbox', boxLabel: 'Remember me?', id: 'RememberMeField' },
                        { xtype: 'tbfill' },
                        { text: 'Login', xtype: 'button', handler:

                            function () {

                                // create a request to for login.
                                Ext.Ajax.request({
                                    url: '/Home/Login',
                                    method: 'POST',
                                    params: {
                                        username: Ext.getCmp('UsernameField').getValue(),
                                        password: Ext.getCmp('PasswordField').getValue(),
                                        rememberme: Ext.getCmp('RememberMeField').getValue()
                                    },
                                    success: function (response) {

                                        var responseObj = Ext.decode(response.responseText);
                                        console.log(responseObj);

                                        if (responseObj.success == true) {
                                            window.location = responseObj.data.url;
                                        } else {
                                            Ext.Msg.alert('Login failed!', responseObj.data.errorMessage);
                                        }

                                    },

                                    failure: function (response, opts) {
                                        console.log("failed");
                                    }
                                    //                                    headers: { 'Content-Type': 'application/json' }
                                });

                            }
                        }
                    ],
                    layout: 'fit'
                }).show();

            });

        </script>
    </head>
    <body>
    </body>
</html>
@*@section scripts {
    <script type="text/javascript">
        var systemTitle = 'Ideas to realize';
        var systemVersion = '@ViewBag.Version';
        var loginName = ' | Logged in as <a id="settings-link" href="/Home/Settings" title="Settings for Fredrik Malmström">Fredrik Malmström</a>';

        var getMainToolbarButtons = function () {
            return [
             // { xtype: 'button', text: 'Administration', scale: 'large', iconCls: 'icon32_settings', action: 'settings', cls: 'large-text' },
                {xtype: 'button', text: 'Dashboard', scale: 'large', iconCls: 'icon32_home', action: 'dashboard', cls: 'large-text' },
                { xtype: 'button', text: 'News and challenges', scale: 'large', iconCls: 'icon32_info', action: 'news', cls: 'large-text' },
                { xtype: 'button', text: 'My proposals', scale: 'large', iconCls: 'icon32_properties', action: 'myproposals', cls: 'large-text' },
             // { xtype: 'button', text: 'Handling cases', scale: 'large', iconCls: 'icon32_edit-page', action: 'cases', cls: 'large-text' },
             // { xtype: 'button', text: 'Follow up', scale: 'large', iconCls: 'icon32_list', action: 'followups', cls: 'large-text' },
                { xtype: 'button', text: 'Search', scale: 'large', iconCls: 'icon32_find', action: 'search', cls: 'large-text' },
                { xtype: 'tbfill' },
                { xtype: 'button', text: 'Help', scale: 'large', iconCls: 'icon32_help-book', action: 'help', cls: 'large-text' },
                { xtype: 'button', text: 'Logout', scale: 'large', iconCls: 'icon32_exit', action: 'logout' }
            ];
        }; 


    </script>
}
*@